class @CustomView extends Backbone.View
    initialize: ->
        $(@el).off()
        Loading.Start()
        if !@silent? || !@silent
            $(window).off("scroll")
        _.bindAll(@)
        @model.view = @

    Navigate: (url, trigger, replace)->
        Backbone.history.navigate(url.replace(window.UrlPrefix,''),
        {
            trigger: trigger
            replace: replace 
        })

    GetTemplate: (url, func) ->
        Utilites.GetTemplate(url, func, @initializeValidate)

    initializeValidate: ->
        form = $(@el).find("form")
        form.find("input, textarea, select").each(() ->
            $(@).Validator()
        )

    IsValid: ->
        if $(@el).find("fieldset").find("div[data-error-message]").length
            return false
        return true


class Utilites
    @template:[]

    @GetTemplate: (url, func, customFunc) ->
        resolvedUrl = url
        if (Settings.Compress.IsEnabled)
            resolvedUrl = url.replace("/myLibrary/", '/myLibrary/Content/') + '.html'
        cashedTemplate = Utilites.template[url+Settings.Version]

        if (typeof (cashedTemplate) == 'undefined')
            $.ajax({
                url: resolvedUrl
                cache: true
                success: (template)->
                    compiledTemplate = _.template(template)
                    Utilites.template[url] = compiledTemplate
                    func(compiledTemplate)
                    customFunc()
                    Loading.Stop()
            })
        else
            func(cashedTemplate)
            customFunc()
            Loading.Stop()